/**
 * @default 数据库列表操作
 * @author 盘挂他爹
 */

import { IList } from "./types"
import { listModels } from "../../model/listModel"
console.log("listModels", listModels);

import {  QueryTypes } from "sequelize"


import { seq } from "../../db"
import { ILikeListOne, ListPandaKill } from "../../model/listModel/listPandaKill"
class ListService {

    /**
     * 获取list数据
     * @param listInfo IList类型 listName, page, pageSize
     */
    async getListContent({page = 1, pageSize = 10}: IList) {
        const num = page * pageSize
        
        // "id": 4,
        //         "name": "09",
        //         "label": "我们都爱大酒神",
        //         "avatar": "",
        //         "trends": "伍声只爱冷雨萱",
        //         "video_thumbnail": "",
        //         "status": true,
        //         "createdAt": "2021-11-01T14:28:26.000Z",
        //         "updatedAt": "2021-11-01T14:28:26.000Z"
        const lists = await ListPandaKill.findAll({
            where: {
                status: 1
            },
            offset: 0,
            limit: num,
            attributes: { exclude: ['status'] },

        })

        console.log("lists", lists);
        
        return lists
        
    }

//like_list_one
    async addListContentOne(listData: ILikeListOne) {

        //批量创建
        const res = await ListPandaKill.bulkCreate(listData)
        console.log("批量", res);
        return res

    }

//删除选项
async delListContentOne(delList: any[]) {
    // const res = await LikeListOne.bulkCreate(delList)
    console.log("del", delList);
    
    let i = 0
    while(i < delList.length) {
        try {
            console.log("i", i);
            
            const res = await ListPandaKill.update({status: false}, {
                where: {
                    id: delList[i].id
                    // id: 1
                }
            })
            if (res[0] < 1) return false
            console.log("更新", res);
            
        } catch (err) {
            console.log("err", err.message);
            
            return false
        }
        i++
    }

    return true
    // console.log("res",res);
    
}    

}

export default new ListService()